<?php

namespace App\Http\Controllers\Api;

use Qiniu\Auth;
use App\Models\School;
use App\Traits\ApiResponse;
use App\Http\Controllers\Controller;

/**
 * @OA\Tag(
 *     name="通用接口",
 *     description="通用接口"
 * )
 */
class CommonController extends Controller
{
    use ApiResponse;
    /**
     * 获取七牛云OSS上传签名
     * 
     * @OA\Get(
     *     path="/api/common/qiniu-oss-sign",
     *     summary="获取七牛云OSS上传签名",
     *     description="获取七牛云OSS上传所需的token签名",
     *     tags={"通用接口"},
     *     @OA\Response(
     *         response=200,
     *         description="获取成功",
     *         @OA\JsonContent(
     *             @OA\Property(property="status", type="string", example="success", description="响应状态"),
     *             @OA\Property(property="code", type="integer", example=200, description="响应码"),
     *             @OA\Property(
     *                 property="data",
     *                 type="object",
     *                 @OA\Property(property="token", type="string", example="eyJ0eXBlIjoiQXV0aGVudGljYXRpb24iLCJhY2Nlc3NLZXkiOiJ0ZXN0IiwiY2FsbGJhY2tVcmwiOiJodHRwOi8vZXhhbXBsZS5jb20vY2FsbGJhY2siLCJkZWFkbGluZSI6MTYzNTY3ODk5OX0=", description="上传token"),
     *                 @OA\Property(property="domain", type="string", example="http://example.com", description="上传域名")
     *             ),
     *             @OA\Property(property="message", type="string", example="操作成功", description="响应消息")
     *         )
     *     ),
     *     @OA\Response(
     *         response=500,
     *         description="服务器错误",
     *         @OA\JsonContent(
     *             @OA\Property(property="status", type="string", example="server error", description="响应状态"),
     *             @OA\Property(property="code", type="integer", example=500, description="响应码"),
     *             @OA\Property(property="data", type="object", example={}, description="响应数据"),
     *             @OA\Property(property="message", type="string", example="Internal Error!", description="错误信息")
     *         )
     *     )
     * )
     */
    public function getQiniuOssSign()
    {
        $auth = new Auth(env('QINIU_ACCESS_KEY'), env('QINIU_SECRET_KEY'));
        $bucket = env('QINIU_BUCKET');
        $token = $auth->uploadToken($bucket);

        return $this->success([
            'token' => $token,
            'domain' => env('QINIU_DOMAIN'),
        ]);
    }

    /**
     * 获取学校列表
     * 
     * @OA\Get(
     *     path="/api/common/school-list",
     *     summary="获取学校列表",
     *     description="获取所有学校的ID和名称列表",
     *     tags={"通用接口"},
     *     @OA\Response(
     *         response=200,
     *         description="获取成功",
     *         @OA\JsonContent(
     *             @OA\Property(property="status", type="string", example="success", description="响应状态"),
     *             @OA\Property(property="code", type="integer", example=200, description="响应码"),
     *             @OA\Property(
     *                 property="data",
     *                 type="array",
     *                 @OA\Items(
     *                     type="object",
     *                     @OA\Property(property="id", type="integer", example=1, description="学校ID"),
     *                     @OA\Property(property="name", type="string", example="清华大学", description="学校名称")
     *                 )
     *             ),
     *             @OA\Property(property="message", type="string", example="操作成功", description="响应消息")
     *         )
     *     ),
     *     @OA\Response(
     *         response=500,
     *         description="服务器错误",
     *         @OA\JsonContent(
     *             @OA\Property(property="status", type="string", example="server error", description="响应状态"),
     *             @OA\Property(property="code", type="integer", example=500, description="响应码"),
     *             @OA\Property(property="data", type="object", example={}, description="响应数据"),
     *             @OA\Property(property="message", type="string", example="Internal Error!", description="错误信息")
     *         )
     *     )
     * )
     */
    public function getSchoolList()
    {
        $schoolList = School::select('id', 'name')->get();
        return $this->success($schoolList);
    }
    
}
